#ifndef SERVICEMANAGER_H
#define SERVICEMANAGER_H

#include <QObject>
#include <QDBusContext>
#include <QMap>
#include <QHash>
#include <gudev/gudev.h>

class Connection;

class ServiceManager : public QObject, protected QDBusContext
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "org.ukui.IndexFramework.Host.ServiceManager")
public:
    explicit ServiceManager(QObject *parent = nullptr);

signals:
    void serviceSetuped(quint32 uid);

public slots:
    void initSystemBus();
    void setupService();
    QString queryFileFullpath(const QString &uuid, quint64 id);
    quint64 queryFileID(const QString &uuid, const QString &filePath);

    void test(QString msg);
    void test2(const QByteArray &buffer);
    void handleMountEvent(uint32_t pid, std::string command, bool isMount, std::string devName, uint64_t devNum);
    void handleFileEventV2(uint32_t pid, std::string command, uint32_t eventType, uint64_t srcDev, uint64_t srcIno, std::string srcPath, uint64_t dstDev, uint64_t dstIno, std::string dstPath);

private slots:
    void handleFileEventV1(QString event);
    void handleFileEventFromProtobuf(const QByteArray &buffer);

private:
    QMap<quint32, Connection*> m_connections;
    GUdevClient *m_udevClient = nullptr;

    QMap<dev_t, std::pair<std::string, std::string>> m_devCache;
    QHash<QString, std::pair<std::string, dev_t>> m_mountpointsCache;
};

#endif // SERVICEMANAGER_H
